object BinTree {
	def main (): Unit = {
	
		/*if ((new Tree().createTestTree().printPostOrder())==0) println("End");
		if ((new Tree().createTestTree().printPreOrder())==0) println("End");*/
		if ((new Tree().createTestTree().printInOrder())==0) println("End");
	}
}

class Tree{
		var node: Int;
		var left: Tree;
		var right: Tree;
		var hasLeft: Bool;
		var hasRight: Bool;

		def init(n:Int):Int = {
			hasLeft = false;
			hasRight = false;
			node = n;
			return 0;	
		}

		def setLeft(l:Tree):Int = {
			left = l;
			hasLeft = true;
			return 0;
		}
		
		def setRight(r:Tree):Int = {
			right = r;
			hasRight = true;
			return 0;
		}

		def createTestTree():Tree = {
			// creates an example tree of 6 nodes
			var trash: Int;

			var l : Tree;
			var r : Tree;
			var ll : Tree;
			var lr : Tree;
			var lrl : Tree;

			//root = new Tree();
			l = new Tree();			
			r = new Tree();			
			ll = new Tree();			
			lr = new Tree();			
			lrl = new Tree();

			node = 5;
			trash = l.init(2);
			trash = ll.init(1);
			trash = lr.init(4);
			trash = lrl.init(3);
			trash = r.init(6);

			trash = this.setLeft(l);
			trash = this.setRight(r);
			trash = l.setLeft(ll);
			trash = l.setRight(lr);
			trash = lr.setLeft(lrl);

			return this;
		}
		
		//print methods
		def printPostOrder():Int = {
			var trash: Int;
			if (hasLeft) trash = left.printPostOrder();
			if (hasRight) trash = right.printPostOrder();
			println(node);
			return 0;
		}

		def printPreOrder():Int = {
			var trash : Int;
			println(node);
			if (hasLeft) trash = left.printPreOrder();
			if (hasRight) trash = right.printPreOrder();
			return 0;
		}

		def printInOrder():Int = {
			var trash: Int;
			if (hasLeft) trash = left.printInOrder();
			println(node);
			if (hasRight) trash = right.printInOrder();
			return 0;
		}

		

}




